const gameVue =  new Vue({
    el: '#ninelineDiv',
    data: {
      name:"",
      subForm : {
        difen : 9, 
        userId:"",
        
      },
      inter : null,
      views:[[-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1]],
      winLines:[],
      freeCount:0,
      wins:{lineScore:0,jackpotScore:0},
      gameInfo :{},
      statInfo : {}
    },
    mounted (){
      setInterval(() => {
        this.getStatData()
      },2000)
    },
    methods :{

      getStatData: async function(){
        let result = await this._post("/game/stat", {
          userId:this.subForm.userId,
        })
        this.statInfo = result;
      },
      clearUserData : async function(){
        let result = await this._post("/game/clearUserData", {
          userId: this.subForm.userId
        });
        this.getStatData();
      },
      stopGame : async function(){
          clearInterval(this.inter);
      },
      clearSystemData : async function(){
        let result = await this._post("/game/clearSystemData", {
        });
        this.getStatData();
      },
      autoGame : async function(){
        this.inter = setInterval(() => {
          this.startGame()
        },2000)
      },
      startGame: async function(){
        let result = await this._post("/game/start", {
          userId:this.subForm.userId,
          betAmount:this.subForm.difen
        })
        console.log(result)
        this.views = result.views;
        this.winLines = result.result.winLines;
        this.freeCount = result.result.freeCount;
        this.wins = result.result.wins;
        this.getStatData();
      },
      _post :function(url, data = {},orgin, type = 'application/json') {
        let self = this;
        return new Promise((resolve, reject) => {
          axios.post(url, data, {
            headers: {
              'Content-Type': type
            }
          }).then(response => {
            if(response.data.code!=0 && response.data.message){
              self.message = response.data.message
              return;
            }
            if(orgin){
              resolve(response.data)
            }else{
              resolve(response.data)
            }
          }, err => {
            console.log(err)
            reject(err)
          })
        })
      }
    }
})

